const db = require('../../db')

const router = require('express').Router()



// logitics面图
router.get('/logistics', (req, res) => {
  // console.log(req.query);
  let pagenum = Number(req.query.pagenum)
  let pagesize = Number(req.query.pagesize)
  // // 翻页
  let offset = (pagenum - 1) * pagesize
  // where title like ${name}
  // let sql = `select * from ebook where title like ${name} order by id limit ${offset},${pagesize};select count(*) total from ebook where title like ${name}`
  let sql = `select * from ebook where fele= '后勤' order by id limit ${offset},${pagesize};select count(*) total from ebook where fele= '后勤'`

  db.query(sql, (error, result, fields) => {
    if (error) {
      res.json({
        'code': 400,
        'error': '查询出错'
      })
    } else {
      res.json({
        'code': 200,
        'data': result[0],
        'total': result[1][0].total
      })
      // console.log(result);
    }
  })
})

router.get('/finance', (req, res) => {
  // console.log(req.query);
  let pagenum = Number(req.query.pagenum)
  let pagesize = Number(req.query.pagesize)
  // // 翻页
  let offset = (pagenum - 1) * pagesize
  // where title like ${name}
  // let sql = `select * from ebook where title like ${name} order by id limit ${offset},${pagesize};select count(*) total from ebook where title like ${name}`
  let sql = `select * from ebook where fele= '财务' order by id limit ${offset},${pagesize};select count(*) total from ebook where fele= '财务'`

  db.query(sql, (error, result, fields) => {
    if (error) {
      res.json({
        'code': 400,
        'error': '查询出错'
      })
    } else {
      res.json({
        'code': 200,
        'data': result[0],
        'total': result[1][0].total
      })
      // console.log(result);
    }
  })
})


router.get('/abapbasis', (req, res) => {
  // console.log(req.query);
  let pagenum = Number(req.query.pagenum)
  let pagesize = Number(req.query.pagesize)
  // // 翻页
  let offset = (pagenum - 1) * pagesize

  let sql = `select * from ebook where fele= 'abapbasis' order by id limit ${offset},${pagesize};select count(*) total from ebook where fele= 'abapbasis'`

  db.query(sql, (error, result, fields) => {
    if (error) {
      res.json({
        'code': 400,
        'error': '查询出错'
      })
    } else {
      res.json({
        'code': 200,
        'data': result[0],
        'total': result[1][0].total
      })
      // console.log(result);
    }
  })
})

module.exports = router